package com.fufufu.mail.coupon.service.impl;

import com.fufufu.common.to.SkureductionTo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fufufu.common.utils.PageUtils;
import com.fufufu.common.utils.Query;

import com.fufufu.mail.coupon.dao.SkuFullReductionDao;
import com.fufufu.mail.coupon.entity.SkuFullReductionEntity;
import com.fufufu.mail.coupon.service.SkuFullReductionService;


@Service("skuFullReductionService")
public class SkuFullReductionServiceImpl extends ServiceImpl<SkuFullReductionDao, SkuFullReductionEntity> implements SkuFullReductionService {

    @Override
    public void saveSkuReductions(List<SkureductionTo> skuReductionTos) {
        if (skuReductionTos == null || skuReductionTos.size() == 0) {
            return;
        }
        List<SkuFullReductionEntity> skuFullReductionEntities = skuReductionTos.stream().map((skuReduction) -> {
            SkuFullReductionEntity skuFullReductionEntity = new SkuFullReductionEntity();
            BeanUtils.copyProperties(skuReduction, skuFullReductionEntity);
            return skuFullReductionEntity;
        }).collect(Collectors.toList());
        this.saveBatch(skuFullReductionEntities);
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SkuFullReductionEntity> page = this.page(
                new Query<SkuFullReductionEntity>().getPage(params),
                new QueryWrapper<SkuFullReductionEntity>()
        );

        return new PageUtils(page);
    }

}